<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/commons/global.jsp" %>
<script type="text/javascript">
    var appBaseDataGrid;
    $(function() {
        appBaseDataGrid = $('#appBaseDataGrid').datagrid({
            url : '${path }/appBase/dataGrid',
            striped : true,
            rownumbers : true,
            pagination : true,
            singleSelect : true,
            idField : 'id',
            sortName : 'id',
            sortOrder : 'asc',
            pageSize : 20,
            pageList : [ 10, 20, 30, 40, 50, 100, 200, 300, 400, 500 ],
            frozenColumns : [ [ {
                title : 'id',
                field : 'id',
                width : 40,
                hidden : true
            } ] ],
            columns : [ [{
                field : 'type',
                title : '数据类型',
                width : 170
            },{
                field : 'key',
                title : '数据key',
                width : 80
            }, {
                field : 'value',
                title : '数据值',
                width : 200
            },{
                width : '60',
                title : '删除',
                field : 'delFlag',
                sortable : true,
                formatter : function(value, row, index) {
                    switch (value) {
                        case 0:
                            return '否';
                        case 1:
                            return '是';
                    }
                }
            },{
                width : '150',
                title : '创建时间',
                field : 'createTime',
                sortable : true
            }, {
                width : '100',
                title : '数据',
                field : 'percentage',
                sortable : true
            }, {
                field : 'action',
                title : '操作',
                width : 130,
                formatter : function(value, row, index) {
                    var str = '';
                    <shiro:hasPermission name="/appBase/edit">
                    str += $.formatString('<a href="javascript:void(0)" class="appBase-easyui-linkbutton-edit" data-options="plain:true,iconCls:\'fi-pencil icon-blue\'" onclick="editAppBaseFun(\'{0}\');" >编辑</a>', row.id);
                    </shiro:hasPermission>
                    <shiro:hasPermission name="/appBase/delete">
                    str += '&nbsp;&nbsp;|&nbsp;&nbsp;';
                    str += $.formatString('<a href="javascript:void(0)" class="appBase-easyui-linkbutton-del" data-options="plain:true,iconCls:\'fi-x icon-red\'" onclick="deleteAppBaseFun(\'{0}\');" >删除</a>', row.id);
                    </shiro:hasPermission>
                    return str;
                }
            } ] ],
            onLoadSuccess:function(data){
                $('.appBase-easyui-linkbutton-del').linkbutton({text:'删除'});
                $('.appBase-easyui-linkbutton-edit').linkbutton({text:'编辑'});
            },
            toolbar : '#appBaseToolbar'
        });
    });

    function editAppBaseFun(id) {
        if (id == undefined) {
            var rows = appBaseDataGrid.datagrid('getSelections');
            id = rows[0].id;
        } else {
            appBaseDataGrid.datagrid('unselectAll').datagrid('uncheckAll');
        }
        parent.$.modalDialog({
            title : '编辑',
            width : 500,
            height : 300,
            href : '${path }/appBase/editPage?id=' + id,
            buttons : [ {
                text : '确定',
                handler : function() {
                    parent.$.modalDialog.openner_dataGrid = appBaseDataGrid;//因为添加成功之后，需要刷新这个dataGrid，所以先预定义好
                    var f = parent.$.modalDialog.handler.find('#appBaseEditForm');
                    f.submit();
                }
            } ]
        });
    }
    

    function deleteAppBaseFun(id,delFlag) {
//        if(delFlag == 0){
            parent.$.messager.alert('提示', '不允许删除', 'info');
                return ;
//        }
    }

    function addAppBaseFun() {
        parent.$.modalDialog({
            title : '添加',
            width : 500,
            height : 300,
            href : '${path }/appBase/addPage',
            buttons : [ {
                text : '添加',
                handler : function() {
                    parent.$.modalDialog.openner_DataGrid = appBaseDataGrid;//因为添加成功之后，需要刷新这个DataGrid，所以先预定义好
                    var f = parent.$.modalDialog.handler.find('#appBaseAddForm');
                    f.submit();
                }
            } ]
        });
    }

</script>
<div class="easyui-layout" data-options="fit:true,border:false">
    <div data-options="region:'center',fit:true,border:false">
        <table id="appBaseDataGrid" data-options="fit:true,border:false"></table>
    </div>
</div>
<div id="appBaseToolbar" style="display: none;">
    <shiro:hasPermission name="/appBase/add">
        <a onclick="addAppBaseFun();" href="javascript:void(0);" class="easyui-linkbutton" data-options="plain:true,iconCls:'fi-plus icon-green'">添加</a>
    </shiro:hasPermission>
</div>